﻿<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="util.JdbcUtil" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="bean.CustomerBean" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
  <head>
    <title>customer</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <link href="resources/css/axure_rp_page.css" type="text/css" rel="stylesheet"/>
    <link href="data/styles.css" type="text/css" rel="stylesheet"/>
    <link href="files/customer/styles.css" type="text/css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="layui/css/laytable.css">
    <script src="resources/scripts/jquery-3.2.1.min.js"></script>
    <script src="resources/scripts/axure/axQuery.js"></script>
    <script src="resources/scripts/axure/globals.js"></script>
    <script src="resources/scripts/axutils.js"></script>
    <script src="resources/scripts/axure/annotation.js"></script>
    <script src="resources/scripts/axure/axQuery.std.js"></script>
    <script src="resources/scripts/axure/doc.js"></script>
    <script src="resources/scripts/messagecenter.js"></script>
    <script src="resources/scripts/axure/events.js"></script>
    <script src="resources/scripts/axure/recording.js"></script>
    <script src="resources/scripts/axure/action.js"></script>
    <script src="resources/scripts/axure/expr.js"></script>
    <script src="resources/scripts/axure/geometry.js"></script>
    <script src="resources/scripts/axure/flyout.js"></script>
    <script src="resources/scripts/axure/model.js"></script>
    <script src="resources/scripts/axure/repeater.js"></script>
    <script src="resources/scripts/axure/sto.js"></script>
    <script src="resources/scripts/axure/utils.temp.js"></script>
    <script src="resources/scripts/axure/variables.js"></script>
    <script src="resources/scripts/axure/drag.js"></script>
    <script src="resources/scripts/axure/move.js"></script>
    <script src="resources/scripts/axure/visibility.js"></script>
    <script src="resources/scripts/axure/style.js"></script>
    <script src="resources/scripts/axure/adaptive.js"></script>
    <script src="resources/scripts/axure/tree.js"></script>
    <script src="resources/scripts/axure/init.temp.js"></script>
    <script src="resources/scripts/axure/legacy.js"></script>
    <script src="resources/scripts/axure/viewer.js"></script>
    <script src="resources/scripts/axure/math.js"></script>
    <script src="resources/scripts/axure/jquery.nicescroll.min.js"></script>
    <script src="data/document.js"></script>
    <script src="files/customer/data.js"></script>
    <script type="text/javascript">
      $axure.utils.getTransparentGifPath = function() { return 'resources/images/transparent.gif'; };
      $axure.utils.getOtherPath = function() { return 'resources/Other.html'; };
      $axure.utils.getReloadPath = function() { return 'resources/reload.html'; };
    </script>
    <script src="${pageContext.request.contextPath }/js/jquery.js"></script>
    <script >
      function add(cid){
        location.href="customeradd.jsp";
      }

      function modify(cid){
        var falg= confirm("确认修改吗？？？");
        if(falg){
          location.href="customermodify?cid="+cid;
        }
      }
      function del(cid){
        var falg= confirm("确认删除吗？？？");
        if(falg){
          location.href="customerdelete?cid="+cid;
        }
      }

    </script>
    <style>
      .cont{
        position: relative;
      }
      #u144_div{
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        padding-top: 40px;
      }
      #cid,#name{
        width:200px;
        height: 30px;
      }
      #sub{
        width: 70px;
        height: 30px;
        background-color:rgba(0, 121, 254, 0.5);
        border-radius:3px;
        border-width:0px;
        font-family:'微软雅黑', sans-serif;
        font-weight:400;
        font-style:normal;
        font-size:14px;
        color:#FFFFFF;
        line-height:20px;
      }
      .table_huowu{
        position: absolute;
        top: 120px;
        left: 50px;
      }
      .table_huowu table{
        border-collapse:collapse;
        width: 800px;
      }
      td{
        white-space: nowrap;
      }
    </style>
    <%
      String sql ="SELECT * FROM customer";
      try {
        PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql);
        ResultSet set = ps.executeQuery();

        ArrayList<CustomerBean> arr = new ArrayList<CustomerBean>();
        while (set.next()){
          CustomerBean cu = new CustomerBean();
          cu.setCid(set.getInt(1));
          cu.setName(set.getString(2));
          cu.setPerson(set.getString(3));
          cu.setTel(set.getString(4));
          cu.setEmail(set.getString(5));
          cu.setAddress(set.getString(6));
          arr.add(cu);
        }
        session.setAttribute("arr", arr);
      } catch (Exception e) {
        e.printStackTrace();
      }
    %>
  </head>
  <body>
    <div id="base" class="">

      <!-- Unnamed (矩形) -->
      <div id="u142" class="ax_default box_1">
        <div id="u142_div" class="cont">
          <div class="table_huowu">
            <table class="layui-table" >
              <thead>
              <tr>
                <th>客户id</th>
                <th>公司</th>
                <th>客户名</th>
                <th>联系电话</th>
                <th>电子邮件</th>
                <th>地址</th>
                <th>操作</th>
              </tr>
              </thead>
              <tbody id="tbody">
              <c:forEach items="${arr}" var="cu">
                <tr>
                  <td>${cu.cid}</td>
                  <td>${cu.name}</td>
                  <td>${cu.person}</td>
                  <td>${cu.tel}</td>
                  <td>${cu.email}</td>
                  <td>${cu.address}</td>

                  <td>
                    <input type="button" value="删除" onclick="del(${cu.cid })" />
                    <input type="button" value="修改" onclick="modify(${cu.cid })" />
                  </td>
                </tr>
              </c:forEach>
              </tbody>
            </table>
          </div>
        </div>
        <div id="u142_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u143" class="ax_default _文本段落">
        <div id="u143_div" class=""></div>
        <div id="u143_text" class="text ">
          <p><span>客户信息管理</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u144" class="ax_default box_1">
        <div id="u144_div" class="">
          <input id="cid" placeholder="客户ID" type="text"/>
          <input type="text" id="name" placeholder="公司名称"/>
          <input type="submit"id="sub" value="筛选" onclick="hunt()">
        </div>
        <div id="u144_text" class="text " style="display:none; visibility: hidden">
          <p></p >
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u148" class="ax_default box_1">
        <div id="u148_div" class=""></div>
        <div id="u148_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (图片 ) -->
      <div id="u149" class="ax_default _图片_">
        <img id="u149_img" class="img " src="images/customer/u149.png"/>
        <div id="u149_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u150" class="ax_default label">
        <div id="u150_div" class=""></div>
        <div id="u150_text" class="text ">
          <p><span>筛选</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u151" class="ax_default box_1">
        <div id="u151_div" class=""></div>
        <div id="u151_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (SVG) -->
      <div id="u152" class="ax_default _图片_">
        <img id="u152_img" class="img " src="images/customer/u152.svg"/>
        <div id="u152_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u153" class="ax_default label">
        <div id="u153_div" class=""></div>
        <div id="u153_text" class="text ">
          <p><span>列表</span></p>
        </div>
      </div>


      <!-- Unnamed (矩形) -->
      <div id="u155" class="ax_default button">
        <div id="u155_div" class=""></div>
        <div id="u155_text" class="text ">
          <p><span onclick="add(${cu.cid})">添加</span></p>
        </div>
      </div>
    </div>
    <script src="resources/scripts/axure/ios.js"></script>
  <script>
    function hunt(){
      var cid = $("#cid").val();
      var name = $("#name").val();
      if (cid==null &&name==null){
        location.href="customer.jsp";
      }
      $.ajax({
        url : "customerhunt?cid="+cid+"&name="+name,//提交地址
        type : "post",//提交方式（get,post）
        dataType : "json",//指定服务器返回的数据类型
        success : function(data) {//请求成功后的回调函数
          console.log(data);
          $("#tbody").empty(); //删除匹配的元素集合中所有的子节点（就是不重复执行）
          var trStr = "";
          for (var i = 0; i < data.length; i++) {
            trStr += "<tr><td>" + data[i].cid +
                    "</td><td>" + data[i].name +
                    "</td><td>" + data[i].person +
                    "</td><td>" + data[i].tel +
                    "</td><td>" + data[i].email +
                    "</td><td>" + data[i].address +
                    "</td><td>" + " <input type='button' value='删除' onclick='del(${cu.cid})' />"
                    +"<input type='button' value='修改' onclick='modify(${cu.cid})' />"+
                    "</td></tr>"
          }
          $("#tbody").show().append(trStr);//向<tbody>内部追加内容
        },
        error : function() {
          alert('请求失败');
        }
      });
    }
  </script>
  </body>
</html>
